home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / COLOR.H < prev    next >
C/C++ Source or Header  |  1992-01-22  |  3KB  |  92 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * A color is defined by rgb intensities and usually accessed by name.
  25.  */
  26.  
  27. #ifndef color_h
  28. #define color_h
  29.  
  30. #include <InterViews/resource.h>
  31.  
  32. /*
  33.  * Color intensity should be subrange 0..65535, but for compatibility
  34.  * reasons it is an integer.
  35.  */
  36. typedef unsigned ColorIntensity;
  37.  
  38. class Color : public Resource {
  39. public:
  40.     Color(ColorIntensity r, ColorIntensity g, ColorIntensity b);
  41.     Color(const char*);
  42.     Color(const char*, int length);
  43.     Color(long pixel);
  44.     ~Color();
  45.  
  46.     void Intensities(ColorIntensity& r, ColorIntensity& g, ColorIntensity& b);
  47.     void DisplayIntensities(
  48.     ColorIntensity& r, ColorIntensity& g, ColorIntensity& b
  49.     );
  50.     int PixelValue();
  51.     boolean Valid();
  52. protected:
  53.     class ColorRep* rep;
  54.     ColorIntensity red, green, blue;
  55. };
  56.  
  57. class ColorRep {
  58. private:
  59.     friend class Color;
  60.  
  61.     ColorRep(long, ColorIntensity&, ColorIntensity&, ColorIntensity&);
  62.     ColorRep(const char*, ColorIntensity&, ColorIntensity&, ColorIntensity&);
  63.     ColorRep(ColorIntensity, ColorIntensity, ColorIntensity);
  64.     ~ColorRep();
  65.  
  66.     int GetPixel();
  67.     void GetIntensities(ColorIntensity&, ColorIntensity&, ColorIntensity&);
  68.     boolean ScanColorFile(const char*, ColorIntensity&, ColorIntensity&, ColorIntensity&);
  69.  
  70.     ColorIntensity red, green, blue;
  71.     int pixel;
  72. };
  73.  
  74. extern Color* black;
  75. extern Color* white;
  76.  
  77. inline void Color::Intensities (
  78.     ColorIntensity& r, ColorIntensity& g, ColorIntensity& b
  79. ) {
  80.     r = red; g = green; b = blue;
  81. }
  82.  
  83. inline void Color::DisplayIntensities (
  84.     ColorIntensity& r, ColorIntensity& g, ColorIntensity& b
  85. ) {
  86.     rep->GetIntensities(r, g, b);
  87. }
  88.  
  89. inline int Color::PixelValue () { return rep->GetPixel(); }
  90.  
  91. #endif
  92.